package com.sgx.learning.luban.homework.constantpool;

import com.sgx.learning.luban.homework.basictype.U2;
import lombok.Data;

import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;


@Data
public class ConstantUtf8Info extends ConstantPoolInfo {
    private short length;
    private byte[] bytes;
    private String bytesValue;

    @Override
    public void read(InputStream is) throws IOException {
        this.length = U2.read(is).getValue();
        byte[] bytes = new byte[length];
        is.read(bytes);
        this.bytes = bytes;
        this.bytesValue = this.getValue();
    }

    public String getValue() {
        return new String(getBytes(), StandardCharsets.UTF_8);
    }

}
